<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>天天生鲜-商品详情</title>
	<link rel="stylesheet" type="text/css" href="/css/reset.css">
	<link rel="stylesheet" type="text/css" href="/css/main.css">
	<link rel="stylesheet" type="text/css" href="/layui/css/layui.css">

</head>
<body>
	<div class="header_con">
		<div th:replace="header::top1"></div>
	</div>

	<div th:replace="search::top2"></div>

	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>	
				<span></span>			
				<ul class="subnav">
					<li><a href="/page/product/list?id=100001" class="fruit">新鲜水果</a></li>
					<li><a href="/page/product/list?id=100002" class="seafood">海鲜水产</a></li>
					<li><a href="/page/product/list?id=100003" class="meet">猪牛羊肉</a></li>
					<li><a href="/page/product/list?id=100004" class="egg">禽类蛋品</a></li>
					<li><a href="/page/product/list?id=100005" class="vegetables">新鲜蔬菜</a></li>
					<li><a href="/page/product/list?id=100006" class="ice">速冻食品</a></li>
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="/">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>

	<div class="breadcrumb">
		<a href="#">全部分类</a>
		<span>></span>
		<a href="#">新鲜水果</a>
		<span>></span>
		<a href="#">商品详情</a>
	</div>

	<div class="goods_detail_con clearfix">
		<div class="goods_detail_pic fl"><img width="350px" height="350px" id="mainImage" src="/images/goods_detail.jpg"></div>

		<div class="goods_detail_list fr">
			<h3 id="name">大兴大棚草莓</h3>
			<!--<p>草莓浆果柔软多汁，味美爽口，适合速冻保鲜贮藏。草莓速冻后，既便于贮藏，又便于外销。</p>-->
			<p>&nbsp;</p>
			<div class="prize_bar">
				<span class="show_pirze">¥<em id="price">16.80</em></span>
				<span class="show_unit" id="subtitle">单  位：500g</span>
			</div>
			<div class="goods_num clearfix">
				<div class="num_name fl">数 量：</div>
				<div class="num_add fl">
					<input type="text" class="num_show fl" value="1">
					<a href="javascript:;" class="add fr">+</a>
					<a href="javascript:;" class="minus fr">-</a>	
				</div> 
			</div>
			<div class="total">总价：<em>16.80元</em></div>
			<div class="operate_btn">
				<a href="javascript:;" class="buy_btn">立即购买</a>
				<a href="javascript:;" class="add_cart" id="addCart">加入购物车</a>
			</div>
		</div>
	</div>

	<div class="main_wrap clearfix">
		<div class="l_wrap fl clearfix">
			<div class="new_goods">
				<h3>新品推荐</h3>
				<ul>
					<li>
						<a href="#"><img src="/images/goods/goods001.jpg"></a>
						<h4><a href="#">进口柠檬</a></h4>
						<div class="prize">￥3.90</div>
					</li>
					<li>
						<a href="#"><img src="/images/goods/goods002.jpg"></a>
						<h4><a href="#">玫瑰香葡萄</a></h4>
						<div class="prize">￥16.80</div>
					</li>
				</ul>
			</div>
		</div>

		<div class="r_wrap fr clearfix">
			<ul class="detail_tab clearfix">
				<li class="active">商品介绍</li>
				<li>评论</li>
			</ul>

			<div class="tab_content">
				<dl>
					<dt>商品详情：</dt>
					<dd id="detail">草莓采摘园位于北京大兴区 庞各庄镇四各庄村 ，每年1月-6月面向北京以及周围城市提供新鲜草莓采摘和精品礼盒装草莓，草莓品种多样丰富，个大香甜。所有草莓均严格按照有机标准培育，不使用任何化肥和农药。草莓在采摘期间免洗可以直接食用。欢迎喜欢草莓的市民前来采摘，也欢迎各大单位选购精品有机草莓礼盒，有机草莓礼盒是亲朋馈赠、福利送礼的最佳选择。 </dd>
				</dl>
			</div>

		</div>
	</div>

	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a>
			<span>|</span>
			<a href="#">联系我们</a>
			<span>|</span>
			<a href="#">招聘人才</a>
			<span>|</span>
			<a href="#">友情链接</a>		
		</div>
		<p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
		<p>电话：010-****888    京ICP备*******8号</p>
	</div>
	<!--<div class="add_jump"></div>-->

	<!--<script src="/js/jquery-1.12.2.js"></script>-->

	<script src="/jquery-2.1.4.js"></script>
	<script src="/layui/layui.js"></script>
	<script src="/mylayer.js"></script>

	<script type="text/javascript">
		layui.use(['form'], function () {
			var form = layui.form;

			var queryString = window.location.search;
			var urlParams = new URLSearchParams(queryString);
			var id = urlParams.get("id");

			$.post(
				'/product/selectById',
				{'id': id},
				function (result) {
					console.log(result);
					if (result.code == 0) {
						$('#name').text(result.data.name);
						$('#subtitle').text(result.data.subtitle);
						$('#price').text(result.data.price);
						$('#detail').html(result.data.detail);
						$('#mainImage').attr('src', '/pic/' + result.data.mainImage);
					}
				},
				'json'
			);

			/*添加购物车*/
			$('#addCart').click(function () {
				addToCart();
			});


			function addToCart() {
				console.log('addToCart');
				$.ajax({
					url:'/cart/add?returnUri=/page/product/detail?id='+ id,
					type:'POST',
					data:{'productId':id},
					success:function (result) {
						if (result.code == 0){
							mylayer.okUrl(result.msg,'/page/cart/list');
						}else{
							mylayer.errorMsg(result.msg);
						}
					},//在ajax方法中添加"complete",complete在ajax中无论ajax请求成功或失败都会执行
					complete:function (xhr,status) {
						//拦截器实现超时跳转到登录页面
						//通过xhr取得响应头
						var REDIRECT = xhr.getResponseHeader("REDIRECT");
						//如果响应头中包含REDIRECT 则说明是拦截器返回的需要重定向的请求
						if (REDIRECT == "REDIRECT"){
							var win = window;
							while (win != win.top){
								win = win.top;
							}
							win.location.href = xhr.getResponseHeader("CONTEXTPATH");
						}
					}
				});
			}

		});
	</script>

	
</body>
</html>